/**
 * 必做任务
 * 逻辑代码
 */
var do_bzrw = function () {
    var foo = require('./foo.js');
    if (
        ui.cxdt.isChecked() ||
        ui.shyh.isChecked() ||
        ui.bhyw.isChecked() ||
        ui.bhrw.isChecked() ||
        ui.xy.isChecked() ||
        ui.smrw.isChecked()
    ) {
        if (ui.cxdt.isChecked()) {
            function do_cxdt() {
                function j_cxdt() {
                    foo.p_hd_f();
                    foo.clk(foo.p_bzrw);
                    foo.clk(foo.p_cxdt, 10, 0, 'wtf') ? foo.clk(foo.p_djdh, 60, 0, 'wtf', j_cxdt, tj_cxdt) : null;
                }
                j_cxdt();
                function tj_cxdt() {
                    function do_cxf() {
                        foo.zjmzx(() => {
                            foo.clk(foo.p_rwbq, 1, 0, 'wtf', null);
                            foo.clk(
                                foo.p_cxf,
                                5,
                                0,
                                'wtf',
                                () => {
                                    foo.p_hd_f();
                                    foo.clk(foo.p_bzrw);
                                    foo.clk(foo.p_cxdt, 10, 0, 'wtf', null, tj_cxdt);
                                },
                                () => {
                                    foo.clk(foo.p_tg, 10, 0, 'wtf', do_cxf);
                                }
                            );
                        });
                    }
                    do_cxf();
                    foo.clk(foo.p_tg, 10, 0, 'wtf', null, 1);
                    foo.clk(foo.p_qd, 10, 0, 'wtf');
                    foo.zjmzx(() => {
                        foo.clk(foo.p_djsy, 5, 0, 'wtf', () => {
                            foo.clk(foo.p_cxf, 5, 0, 'wtf', null, () => {
                                foo.clk(foo.p_tg, 5, 0, 'wtf', null, 1);
                                foo.clk(foo.p_qd, 5, 0, 'wtf');
                            });
                        });
                        sleep(1000);
                        foo.clk(foo.p_djsy, 5, 0, 'wtf');
                    });
                }
            }
            foo.zjmzx(do_cxdt);
            foo.clk(foo.p_gb);
        } //逞凶打图
        if (ui.shyh.isChecked()) {
            cxdt_re_count = 0;
            function do_shyh() {
                j_shyh = function () {
                    foo.p_hd_f();
                    foo.clk(foo.p_bzrw);
                    foo.clk(foo.p_shyh, 10, 0, 'wtf') ? foo.clk(foo.p_djdh, 40, 0, 'wtf', j_shyh, c_shyh) : null;
                };
                j_shyh();
                function c_shyh() {
                    foo.clk(foo.p_tg, 6, 0, 'wtf', null, () => {
                        foo.clk(foo.p_qd, 5, 0, 'wtf');
                    });
                    function do_yh() {
                        foo.zjmzx(() => {
                            foo.clk(foo.p_rwbq);
                            foo.clk(
                                foo.p_yh,
                                2,
                                0,
                                'wtf',
                                () => {
                                    foo.p_hd_f();
                                    foo.clk(foo.p_bzrw);
                                    foo.clk(foo.p_shyh, 2, 0, 'wtf', null, do_yh);
                                },
                                () => {
                                    foo.clk(foo.p_qj, 5, 0, 'wtf', do_yh, () => {
                                        sleep(1000);
                                        foo.clk(foo.p_pz, 5, 0, 'wtf', do_yh, () => {
                                            sleep(2000);
                                            foo.clk(foo.p_qx, 2, 0, 'wtf', null, do_yh);
                                            do_yh();
                                        });
                                    });
                                }
                            );
                        });
                    }
                    do_yh();
                    foo.zjmzx(() => {
                        foo.clk(foo.p_djsy, 5, 0, 'wtf', null, 2);
                    });
                }
            }
            foo.zjmzx(do_shyh);
        } //山河映画
        if (ui.bhyw.isChecked()) {
            function cxz_bhyw() {
                foo.p_hd_f();
                foo.clk(foo.p_tzrw);
                foo.clk(foo.p_bhyw);
                foo.clk(foo.p_qwtz, 10, 0, 'wtf');
                foo.zjmzx(() => {
                    foo.clk(foo.p_zdyw, 10, 0, 'wtf', cxz_bhyw, 1);
                });
            }
            function do_bhyw() {
                foo.p_hd_f();
                foo.clk(foo.p_tzrw);
                foo.clk(foo.p_bhyw);
                if (foo.clk(foo.p_qwtz, 10, 0, 'wtf', cxz_bhyw, 1)) {
                    foo.clk(foo.p_zdyw, 90, 0, 'wtf', cxz_bhyw, () => {
                        foo.clk(foo.p_zdyw);
                        sleep(140000);
                        foo.zjmzx(() => {
                            foo.clk(foo.p_djsy, 5, 0, 'wtf');
                            sleep(1500);
                            foo.clk(foo.p_djsy, 5, 0, 'wtf');
                        });
                    });
                }
            }
            foo.zjmzx(do_bhyw);
        } //帮会演武
        if (ui.bhrw.isChecked()) {
            function do_bhrw() {
                function j_bhrw() {
                    foo.p_hd_f();
                    foo.clk(foo.p_bzrw);
                    foo.clk(foo.p_bhrw, 10, 0, 'wtf', null, () => {
                        if (ui.ztks_bh.isChecked()) {
                            foo.clk(foo.p_rwbq, 2, 0, 'wtf');
                            foo.clk(foo.p_swh, 2, 0, 'wtf');
                            z_bhrw();
                        } else {
                            foo.clk(foo.p_djdh, 30, 0, 'wtf', j_bhrw, z_bhrw);
                        }
                    });
                } //接任务
                j_bhrw();
                function z_bhrw() {
                    if (ui.xl_bhrw.getSelectedItemPosition() == 0) {
                        function z_swh() {
                            foo.clk(
                                foo.p_sbrw,
                                Number(storage.get('configure').outTime_sxbh),
                                0,
                                'wtf',
                                () => {
                                    foo.p_hd_f();
                                    foo.clk(foo.p_bzrw);
                                    foo.clk(
                                        foo.p_bhrw,
                                        10,
                                        0,
                                        'wtf',
                                        () => {
                                            foo.clk(foo.p_gb);
                                        },
                                        z_swh
                                    );
                                },
                                () => {
                                    z_swh();
                                }
                            );
                        }
                        z_swh();
                    } //三星帮会任务
                    if (ui.xl_bhrw.getSelectedItemPosition() == 1) {
                        function z_bdc() {
                            function cz_bdc() {
                                foo.p_hd_f();
                                foo.clk(foo.p_bzrw);
                                foo.clk(foo.p_bhrw, 5, 0, 'wtf', null, z_bdc);
                            }
                            function do_bdc() {
                                foo.clk(foo.p_bdcj, 2, 0, 'wtf');
                                foo.clk(foo.p_tg, 3, 0, 'wtf', do_bdc, z_bdc);
                            }
                            function zd_bdc() {
                                foo.zjmzx(() => {
                                    foo.clk(foo.p_bdc, 2, 0, 'wtf', cz_bdc);
                                });
                                foo.clk(foo.p_tg, 10, 0, 'wtf', zd_bdc, () => {
                                    foo.clk(foo.p_qd, 2, 0, 'wtf');
                                    do_bdc();
                                });
                            }
                            foo.clk(foo.p_sibrw, 5, 0, 'wtf', cz_bdc, () => {
                                sleep(8000);
                                zd_bdc();
                            });
                        }
                        z_bdc();
                    } //四星帮会任务
                    if (ui.xl_bhrw.getSelectedItemPosition() == 2) {
                        function gmbwf() {
                            foo.clk(foo.p_bwf, 2, 0, 'wtf', null, () => {
                                foo.clk(foo.p_qwsh, 2, 0, 'wtf', null, () => {
                                    foo.clk(foo.p_gm, 2, 0, 'wtf', null, () => {
                                        foo.clk(foo.p_qxaqs, 2, 0, 'wtf');
                                        foo.clk(foo.p_gb);
                                        gmbwf();
                                    });
                                });
                            });
                        }
                        function z_bwf() {
                            foo.clk(
                                foo.p_wbrw,
                                5,
                                0,
                                'wtf',
                                () => {
                                    foo.p_hd_f();
                                    foo.clk(foo.p_bzrw);
                                    foo.clk(
                                        foo.p_bhrw,
                                        10,
                                        0,
                                        'wtf',
                                        () => {
                                            foo.clk(foo.p_gb);
                                        },
                                        z_bwf
                                    );
                                },
                                gmbwf
                            );
                        }
                        z_bwf();
                    } //五星帮会任务
                } //循环做
            }
            do_bhrw();
            foo.clk(foo.p_gb);
        } //帮会任务
        if (ui.xy.isChecked()) {
            function do_xy() {
                var count_xy = 0;
                function mzd_tg() {
                    foo.clk(foo.p_gb);
                    foo.clk(foo.p_rwbq, 2, 0, 'wtf');
                    foo.clk(foo.p_qly, 5, 0, 'wtf', null, 9);
                    foo.clk(foo.p_tg, 5, 0, 'wtf', mzd_tg);
                }
                function j_xy() {
                    count_xy++;
                    if (count_xy > 7) {
                        return;
                    }
                    foo.clk(foo.p_rwbq);
                    if (foo.clk(foo.p_qly, 8000)) {
                        c_xy();
                    } else {
                        foo.p_hd_f();
                        foo.clk(foo.p_xxrw);
                        foo.clk(foo.p_xy, 10, 0, 'wtf') ? foo.clk(foo.p_djdh, 10, 0, 'wtf', j_xy, c_xy) : null;
                    }
                }
                function c_xy() {
                    foo.clk(
                        foo.p_hjwl,
                        90,
                        0,
                        'wtf',
                        () => {
                            foo.clk(foo.p_qly, 5000);
                            foo.clk(foo.p_hjwl, 5, 0, 'wtf', null, 2);
                        },
                        1
                    );
                    foo.clk(foo.p_tg, 20, 0, 'wtf');
                    sleep(1000);
                    foo.clk(foo.p_qd, 5, 0, 'wtf');
                    sleep(1000);
                    foo.clk(foo.p_tg, 10, 0, 'wtf');
                    sleep(1000);
                    foo.clk(foo.p_tg, 100, 0, 'wtf');
                    sleep(1000);
                    foo.clk(foo.p_tg, 50, 0, 'wtf');
                    sleep(1000);
                    foo.clk(foo.p_tg, 50, 0, 'wtf');
                    sleep(1000);
                    foo.clk(foo.p_tg, 50, 0, 'wtf');
                    sleep(1000);
                    foo.clk(foo.p_tg, 50, 0, 'wtf');
                    sleep(2000);
                    function zsyc() {
                        mzd_tg();
                        foo.clk(foo.p_xyzsyc, 5, 0, 'wtf', zsyc);
                    }
                    foo.clk(foo.p_xyzsyc, 10, 0, 'wtf', zsyc);
                    sleep(2000);
                    foo.clk(foo.p_tg, 40, 0, 'wtf', mzd_tg);
                    sleep(1000);
                    foo.clk(foo.p_hcylq, 10, 0, 'wtf', null, function () {
                        sleep(60 * 1000);
                    }); //合成
                    sleep(1000);
                    foo.clk(foo.p_gb, 20, 0, 'wtf'); //无法合成则关闭
                }

                j_xy();
            }
            foo.zjmzx(do_xy);
            foo.clk(foo.p_gb);
        } //一千零一个愿望
        if (ui.smrw.isChecked()) {
            var sm_flag = true;
            function do_smrw() {
                if (ui.ztks_sm.isChecked()) {
                    c_smrw();
                } else {
                    j_smrw();
                }
            } //判断是否中途开始
            function j_smrw() {
                foo.p_hd_f();
                foo.clk(foo.p_bzrw);
                foo.clk(foo.p_smrw, 10, 0, 'wtf') ? foo.clk(foo.p_djdh, 60, 0, 'wtf', j_smrw, c_smrw) : null;
            } //接师门任务
            function c_smrw() {
                while (sm_flag) {
                    if (
                        foo.zjmzx(() => {
                            foo.clk(foo.p_rwbq, 1, 0, 'wtf');
                            if (foo.clk(foo.p_sml, 5, 0, 'wtf')) {
                                return true;
                            } else {
                                return false;
                            }
                        })
                    ) {
                        sm_flag = true;
                        sleep(1000);
                        if (foo.clk(foo.p_qwsh, 2, 0, 'wtf')) {
                            foo.clk(foo.p_djgm, 5, 0, 'wtf');
                            foo.clk(foo.p_qxaqs, 2, 0, 'wtf');
                        } else {
                            foo.clk(foo.p_djdh, 2, 0, 'wtf');
                            foo.clk(foo.p_qd);
                            foo.clk(foo.p_tg, 2, 0, 'wtf', null, () => {
                                foo.clk(foo.p_qd, 2, 0, 'wtf');
                            });
                        }
                    } else {
                        foo.p_hd_f();
                        foo.clk(foo.p_bzrw);
                        foo.clk(foo.p_smrw, 10, 0, 'wtf', () => {
                            sm_flag = false;
                        });
                    }
                }
                //使用礼包
                function sysmwp() {
                    foo.zjmzx(() => {
                        foo.clk(foo.p_rwbq, 2, 0, 'wtf');
                        foo.clk(foo.p_sml, 2, 0, 'wtf', null, () => {
                            foo.clk(foo.p_tg, 5, 0, 'wtf', sysmwp, () => {
                                foo.clk(foo.p_qd, 5, 0, 'wtf');
                            });
                        });
                    });
                }
                foo.zjmzx(() => {
                    foo.clk(foo.p_djsy, 5, 0, 'wtf', sysmwp, 2);
                });
            } //做+交;
            foo.zjmzx(do_smrw);
        } //师门任务
    } else {
        console.log('没有选中执行操作');
    }
    foo.zjmzx(()=>{
        toastLog('必做任务结束了');
    });
    
    threads.currentThread().interrupt();
    delete variables.threads.a1;
    layout1.bzrw.setText('开始执行');
};
exports.do_bzrw = do_bzrw;
